/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package backupit.gui.control;

import backupit.gui.BackupListFrame;
import backupit.GUILauncher;
import backupit.core.dirbackup.DirBackup;
import backupit.core.dirbackup.io.DirBackupWriter;
import java.io.IOException;
import javax.swing.JProgressBar;

/**
 *
 * @author dbotelho
 */
public class BackupWriterController extends DirBackupWriter {
    private GUILauncher launcher;
    private BackupListFrame frame;
    private JProgressBar statusbar;

    public BackupWriterController(GUILauncher launcher, JProgressBar statusbar, DirBackup backup) throws IOException {
        super(backup);
        this.launcher = launcher;
        this.frame = launcher.getMainFrame();
        this.statusbar = statusbar;
    }

    @Override
    public void run() {
        statusbar.setStringPainted(true);
        statusbar.setString("Executing");
        statusbar.setMaximum(1);
        statusbar.setIndeterminate(true);
        //frame.update(frame.getGraphics());
        
        this.frame.getStatusLabel().setText("Start backup " + this.getBackup().getName());
        frame.repaint();
        this.setWriter(new FileInfoSetWriterController(launcher, dest_dir.getPath()));
        super.run();
        frame.getStatusLabel().setText("End backup " + this.getBackup().getName());
        statusbar.setIndeterminate(false);
        statusbar.setString("Updated");
        statusbar.setValue(1);
        frame.repaint();
        //frame.update(frame.getGraphics());
        this.launcher.getBackupManager().getBackupManagerGUI().addBackupInfo(getBackupInfo());
        //new ViewBackupInfo(this.frame,super.getBackupInfo()).setVisible(true);
    }
}
